package problems.contest;

import java.util.HashMap;
import java.util.Map;

/**
 * <p></p>
 *
 * @author habitplus
 * @since 2023/3/5 11:01
 */
public class WCT335 {

    /**
     * T3|
     */
    public int findValidSplit(int[] nums) {
        if (nums.length == 1) {
            return -1;
        }
        int minOffset = 0;
        for (int i = 0; i < nums.length; ++i) {
            int left = nums[i];
            for (int j = nums.length - 1; j > minOffset; --j) {
                int gcd = gcd(left, nums[j]);
                if (gcd != 1) {
                    if (j == nums.length - 1) {
                        return -1;
                    }
                    minOffset = j;
                    break;
                }
            }
            if (i == minOffset) {
                break;
            }
        }
        return minOffset;
    }

    private int gcd(int a, int b) {
        while (b != 0) {
            int t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
}
